/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import type { ProColumns } from '@ant-design/pro-table';
import React from 'react';
import { history } from 'umi';
import type { TableColumnsItem } from './type';
import { Space, Tag } from 'antd';
import type { LogColumnItem } from './type';

export const isTimeOutType = {
  '0': '立即发送',
  '1': '定时发送',
};

export const signType = {
  微快递: '【微快递】',
  聚单客: '【聚单客】',
  快宝驿站: '【快宝驿站】',
};

export const sendStatus = {
  build: '未发送',
  wait: '待发送',
  sending: '发送中',
  sent: '已发送',
};

const dataSource = {
  excel: '自主导入',
  script: '脚本导入',
};

export const columns: ProColumns<TableColumnsItem>[] = [
  {
    title: '批次号',
    dataIndex: 'batch_number',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '发送总人数',
    dataIndex: 'phone_cnt',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '生成时间',
    dataIndex: 'create_time',
    search: false,
    align: 'center',
    ellipsis: true,
  },
];

export const logColumns: ProColumns<LogColumnItem>[] = [
  {
    title: '批次号',
    dataIndex: 'batch_number',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
  },
  {
    title: '发送总人数',
    dataIndex: 'phone_cnt',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
  },
  {
    title: '生成时间',
    dataIndex: 'create_time',
    search: false,
    align: 'center',
    width: 160,
    ellipsis: true,
  },
  {
    title: '短信主题',
    dataIndex: 'subject',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
  },
  {
    title: '短信内容',
    dataIndex: 'content',
    search: false,
    align: 'center',
    width: 200,
    ellipsis: true,
  },
  {
    title: '短信签名',
    dataIndex: 'sms_sign',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
    valueEnum: signType,
  },
  {
    title: '数据来源',
    dataIndex: 'data_source',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
    valueEnum: dataSource,
  },
  {
    title: '发送时间',
    dataIndex: 'send_time',
    search: false,
    align: 'center',
    width: 140,
    ellipsis: true,
    render: (_, record) => {
      const { is_timing, send_time } = record;
      return (
        <Space direction='vertical'>
          <span>{send_time}</span>
          {is_timing ? <Tag color='#108ee9'>定时短信</Tag> : null}
        </Space>
      );
    },
  },
  {
    title: '处理状态',
    dataIndex: 'status',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
    valueEnum: sendStatus,
  },
  {
    title: '发送人',
    dataIndex: 'operator',
    search: false,
    align: 'center',
    width: 100,
    ellipsis: true,
  },
  {
    title: '操作',
    valueType: 'option',
    align: 'center',
    width: 80,
    render: (_, record) => {
      return (
        <a
          key={record.id}
          onClick={() => {
            history.push({
              pathname: '/f/ad/marketingsms/details',
              query: { ...record },
            });
          }}
        >
          详情
        </a>
      );
    },
  },
];

export const historyColumns: ProColumns<TableColumnsItem>[] = [
  {
    title: '短信主题',
    dataIndex: 'task_name',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '短信内容',
    dataIndex: 'sms_content',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '发送总人数',
    dataIndex: 'sms_send_num',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '短信签名',
    dataIndex: 'sms_sign',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '发送时间',
    dataIndex: 'sms_send_time',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '导入人',
    dataIndex: 'export_user',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '导入时间',
    dataIndex: 'create_time',
    search: false,
    align: 'center',
    ellipsis: true,
  },
  {
    title: '操作',
    valueType: 'option',
    align: 'center',
    render: (_, record) => {
      return (
        <a
          key={record.id}
          onClick={() => {
            history.push({
              pathname: '/f/ad/marketingsms/historyDetails',
              query: { ...record },
            });
          }}
        >
          查看
        </a>
      );
    },
  },
];
